package cn.zwx.learn.basic.groovy.register;


import groovy.lang.GroovyObject;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @description 注册公共脚本
 * @author zhangwenxue
 * @createTime 2021/4/13 18:30
 **/
public class CommonGroovyRegister {

    private static volatile CommonGroovyRegister INSTANCE = new CommonGroovyRegister();

    private CommonGroovyRegister() {
    }

    private Map<String, GroovyObject> groovyClassMap = new ConcurrentHashMap<>();

    public void put(String name, GroovyObject handler) {
        groovyClassMap.put(name, handler);
    }

    public GroovyObject get(String name) {
        return groovyClassMap.get(name);
    }

    public void remove(String name) {
        groovyClassMap.remove(name);
    }


    public static CommonGroovyRegister getInstance() {
        return INSTANCE;
    }
}
